#include "head.hpp"

int main()
{
    vector<double> x = {0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6, 6.5, 7, 7.5, 8, 8.5, 9, 9.5, 10};
    vector<double> y = {2.9, 2.7, 4.8, 5.3, 7.1, 7.6, 7.7, 7.6, 9.4, 9.0, 9.6, 10, 10.2, 9.7, 8.3, 8.4, 9.0, 8.3, 6.6, 6.7, 4.1};

    // 测试数据
    // vector<double> x = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
    // vector<double> y = {256, 201, 159, 61, 77, 40, 17, 25, 103, 156, 222, 345};

    int N = x.size();
    int p = 2;
    vector<vector<double>> G(p + 1, vector<double>(p + 1));
    for (int i = 0; i < p + 1; i++)
    {
        for (int j = 0; j < p + 1; j++)
        {
            G[i][j] = inner(pow(x, i), pow(x, j));
        }
    }
    cout << "G:" << endl;
    mat_out(G);
    cout << endl;
    
    vector<double> c(p + 1);
    for (int i = 0; i < p + 1; i++)
    {
        c[i] = inner(y, pow(x, i));
    }
    cholesky(G);
    c = lower_tr(G, c);
    vector<double> a = upper_tr(G, c);
    vec_out(a);

    return 0;
}